package com.netflexitysolutions.amazonws.s3.internal.operations;

import com.amazonaws.s3.doc._2006_03_01.GetObject;
import com.amazonaws.s3.doc._2006_03_01.GetObjectResult;
import com.netflexitysolutions.amazonws.s3.S3;
import com.netflexitysolutions.amazonws.s3.S3GetObjectResponse;

public class GetObjectOperation extends OperationExecutor<GetObject, S3GetObjectResponse>{

    private String bucket;
    private String key;
    private boolean loadMetadata;
    private boolean loadData;
    private boolean inlineData;
    
    public GetObjectOperation(S3 s3, String bucket, String key, boolean loadMetadata, boolean loadData, boolean inlineData){
        super(s3);
        this.bucket = bucket;
        this.key = key;
        this.loadMetadata = loadMetadata;
        this.inlineData = inlineData;
        this.loadData = loadData;
    }

    @Override
    protected S3GetObjectResponse call(GetObject request) {
        request.setKey(key);
        request.setBucket(bucket);
        request.setGetData(loadData);
        request.setGetMetadata(loadMetadata);
        request.setInlineData(inlineData);

        injectCredentials(request, "GetObject", getS3().getAccessKey(), getS3().getSecretKey());

        GetObjectResult result = getS3().getService().getObject(request).getGetObjectResponse();
        return new S3GetObjectResponse(result);
    }
}
